import type { Router } from "vue-router";
import { useTagsStore } from "@/store/modules/tags";

export function createTagsGuard(router: Router) {
  router.afterEach((to) => {
    // 排除不需要记录的路由
    if (
      to.meta?.noTag ||
      to.path === "/login" ||
      to.path.startsWith("/redirect") ||
      to.path === "/404"
    ) {
      return;
    }

    const tagsStore = useTagsStore();
    tagsStore.addTag(to);
  });
}
